package com.openxt.nbzj.activity;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.RelativeLayout;

import com.alibaba.fastjson.JSONObject;
import com.openxt.nbzj.R;
import com.openxt.nbzj.fragment.OpenxtBaseActivity;
import com.openxt.nbzj.model.ConfigModel;
import com.openxt.nbzj.model.RemotingModel;
import com.openxt.nbzj.update.AutoUpdateEx;

import butterknife.BindView;
import butterknife.ButterKnife;
import qs.openxt.libs.util.ActivityUtil;

/**
 * Created by 颖杰_2 on 2016/7/5.
 */
public class AccountSettingActivity extends OpenxtBaseActivity implements View.OnClickListener {
    @BindView(R.id.btn_01)
    RelativeLayout btn_01;
    @BindView(R.id.btn_02)
    RelativeLayout btn_02;
    @BindView(R.id.btn_03)
    RelativeLayout btn_03;
    @BindView(R.id.btn_04)
    RelativeLayout btn_04;
    @BindView(R.id.btn_05)
    RelativeLayout btn_05;

    Handler mHandler = new Handler();
    Context mContext = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setBaseStyle(R.layout.account_setting_activity, "我的设置");
        ButterKnife.bind(this);

        mContext = this;

        btn_01.setOnClickListener(this);
        btn_02.setOnClickListener(this);
        btn_03.setOnClickListener(this);
        btn_05.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_01) {//修改密码
            Bundle bundle = new Bundle();
            bundle.putString("url", ConfigModel.ROOTPATH + "index.html#/uptpwd");
            toActivity(WebViewActivity.class, bundle, false);
        } else if (v.getId() == R.id.btn_02) {//更改昵称
            toActivity(NickNameActivity.class);
        } else if (v.getId() == R.id.btn_03) {//更换手机
            Bundle bundle = new Bundle();
            bundle.putString("url", ConfigModel.ROOTPATH + "index.html#/uptphone");
            toActivity(WebViewActivity.class, bundle, false);
        } else if (v.getId() == R.id.btn_05) {//检查更新
            try {
                //调用更新
                JSONObject param = new JSONObject();
                param.put("type", "android");
                param.put("Version", ActivityUtil.getVersion(mContext));
                AutoUpdateEx autoUpdateEx = new AutoUpdateEx(mContext, RemotingModel.SERVERURL + RemotingModel.CHECKVERSION, param, true);
                autoUpdateEx.update();
            } catch (Exception e) {

            }
        }
    }
}